<template>
  <card-group-solt
          @handleClick="changeTab"
          :activeName="activeName"
          :tabPanes="tabPanes"
          :cardLoading="loading"
    >
    <template :slot="'search'" v-if="activeName === 'email_all'">
      <search :type="activeName">
        <!--快捷搜索-->
        <template :slot="'select'">
          <v-select
            :selectOptions="mailCategories"
            @quickSelect="handlerQuickSelect"
            :form="search[activeName].isChildren.nomalForm"></v-select>
        </template>
        <!--搜索框-->
        <template :slot="'inputSearch'">
          <input-search
            :placeHolder="$t('email.pleaseEnter')"
            @quickSearch="normalSearch"
            :form="search[activeName].isChildren.nomalForm"></input-search>
        </template>
        <!--高级搜索-->
        <template  :slot="'advancedSearch'">
          <advanced-search
            :adv="search[activeName].isChildren.adv"
            :pickerName="pickerName"
            :formItemsConfig="formItemsConfig"
            :activeName="activeName"
            @selectChange="handlerSelectChange"
            @advSearch="advSearch"
            @confirmNewItemsConfig="handleConfirmNewItemsConfig"
          ></advanced-search>
        </template>
        <!--展示高级搜索数据-->
        <template :slot="'advSchBadge'">
          <advSchBadge
            :badge="search[activeName].isChildren.adv.badgeList"
            @removeBadge="removeBadge"></advSchBadge>
        </template>
        <!--刷新-->
        <template :slot="'refresh'">
          <refresh  @refresh="handleRefresh" :class="'positionClass'"></refresh>
        </template>
        <!--主动发送邮件-->
        <template :slot="'sendEmail'">
          <sendEmail @send="sendEmail"></sendEmail>
        </template>
      </search>
    </template>
    <!--卡片列表-->
    <template :slot="'cardList'">
      <email-card
        :cardList="cardList"
        :count="count"
        :allCount="allCount"
        :type="type"
        :qu="qu"
        :tabType="activeName"
        :searchStatus="searchStatus"
        :currentAdvSesrch="currentAdvSesrch"
        v-if="!loading"
        @refresh="handleRefresh"
        @changeCardItem="changeCardItem"></email-card>
    </template>
    <!--翻页-->
    <template slot="pagination" v-if="activeName === 'email_all'">
      <pagination
        :customerShow="true"
        :small="search.email_all.pagination.small"
        :currentPage="search.email_all.pagination.currentPage"
        :count="count"
        :type="type"
        :moreFlag="moreFlag"
        :allCount="allCount"
        :tabType="activeName"
        :totalPage="totalPage"
        @turnPage="turnPage"
        @getAllCount="getAllCount"
      >
      </pagination>
    </template>
  </card-group-solt>
</template>
<script>
  import CardGroupSolt from '@/components/public-modules/card/NewIndex'
  import EmailCard from './EmailCard'
  import Search from '@/components/public-modules/card/search/NewIndex.vue'
  import Select from '@/components/public-modules/card/search/Select'
  import InputSearch from '@/components/public-modules/card/search/InputSearch'
  import AdvancedSearch from '@/components/public-modules/card/search/Advanced1Search'
  import AdvSchBadge from '@/components/public-modules/card/search/AdvSchBadge'
  import Pagination from '@/components/public-modules/card/Pagination'
  import Refresh from '../../ui-modules/icon/Refresh'
  import sendEmail from '../../ui-modules/icon/SendEmail.vue'
  import bus from '@/store/eventBus'
  import {deepClone, getFormatDateTime} from '@/utils/m7Utils'
  export default {
    name: 'EmailCardGroup',
    props: {
      currentTabType: String
    },
    data () {
      return {
        allCount: 0,  // count总条数
        loading: true,
        activeName: this.$route.params.tabType || 'email_todo',
        type: 'email',
        pages: 0,     // 总页数
        qu: {},       // 高级搜索问题
        currentShowPage: true, // 当前页
        isbeforeMount: false, // 是否加载过
        pickerName: this.activeName + 'picker',
        searchStatus: '', // 当前搜索卡片的状态
        search: {               // 高级搜索数据
          isAdvSearch: false, // 是否在高级搜索
          isSearch: false,
          mailCategorys: [],
          serviceEmails: [],
          email_todo: {
            searchCard: 'etSearchCard',
            show: false,
            pagination: {
              small: true,
              currentPage: 1
            },
            isChildren: {
              rel: false,
              select: [],
              nomal: true,
              adv: {},
              refresh: false
            }
          },
          email_all: {
            searchCard: 'eaSearchCard',
            show: true,
            pagination: {
              small: true,
              currentPage: 1
            },
            isChildren: {
              lastQuery: null,
              rel: false,
              select: [],
              nomal: true,
              nomalForm: {query: '', value: ''},
              refresh: true,
              adv: {
                form: {
                  fromAddr: '',
                  subject: '',
                  custName: '',
                  createTime: [],
                  lastReceiveTime: [],
                  toAddr: '',
                  category: '',
                  status: '',
                  ownercom: '',
                  initiative: false,
                  processTimeout: false,
                  agent: '',
                  ownerdep: ''
                },
                advSearchOptions: {
                  localed: []
                },
                badgeList: {}
              }
            }
          }
        },
        currentAdvSesrch: null,
        formItemsConfig: null
      }
    },
    // 当前tab发生变化触发
    watch: {
      currentTabType: 'changeTabType'
    },
    mounted () {
      // 邮件跳转路由监听绑定
      bus.$on('emailJumpRoute', (msg) => {
        if (this.currentShowPage) {
          this.routeToMe()
        }
      })
    },
    beforeDestroy () {
      // 邮件跳转路由监听解除绑定
      bus.$off('emailJumpRoute')
    },
    activated () {
      if (this.isbeforeMount) {
        this.currentShowPage = true
        this.routeToMe()
      }
    },
    deactivated () {
      this.currentShowPage = false
    },
    provide () {
      return {
        itemsDisabled: {
          email_all: {
            createTime: true
          }
        }
      }
    },
    beforeMount () {
      // 设置高级搜索默认时间
      this.createTimeInit()
      // 翻页初始化
      this.allCount = 0
      fetchMailList(this, this.activeName, {idle: '', type: 'email_todo'}).then(() => {
        this.loading = false
      })

      // 高级搜索初始化
      Promise.all([
        this.$store.dispatch('getCache', {type: 'serviceEmails'}),
        this.$store.dispatch('getCache', {type: 'mailCategorys'}),
        this.$store.dispatch('getCache', {type: 'custTmpls'}),
        this.$store.dispatch('getCache', {type: 'channelDic'}),
        this.$store.dispatch('getAdvSearchConfig', {searchType: 'EmailCardGroup'}) // 高级搜索布局配置
        // this.$store.dispatch('getCache', {type: 'channelDic'})
      // ]).then(([serviceEmails, mailCategorys, custTmpls, channelDic]) => {
      ]).then(([serviceEmails, mailCategorys, custTmpls, channelDic, config]) => {
        let custTmpl = custTmpls[0] || []
        let statusConfig = custTmpl.statusConfig || {}
        let status = {}
        if (custTmpl.status) {
          status = JSON.parse(JSON.stringify(custTmpl.status))
        }
        // this.stutasSelect = JSON.parse(JSON.stringify(custTmpl.status))
        if (statusConfig) {
          for (let key in status) {
            if (statusConfig[key] && statusConfig[key].status !== 'enabled') {
              delete status[key]
            }
          }
        }
        let finishTypes = getFinishType(this.getChannelDicByType('email'))
        let emailFinish = [{ label: this.$t('public.all'), value: '' }, ...finishTypes]
        let serviceEmailData = [{ label: this.$t('public.all'), value: '' }, ...serviceEmails.map(serviceEmail => ({ label: serviceEmail.email, value: serviceEmail.email }))]
        this.search.mailCategorys = mailCategorys
        let localedOptions = [
          {label: this.$t('email.customerEmailAddress'), name: 'fromAddr', inputType: 'input'},
          {label: this.$t('email.emailSubject'), name: 'subject', inputType: 'input'},
          {label: this.$t('business.customerName'), name: 'custName', inputType: 'input'},
          {label: this.$t('public.createTime'), name: 'createTime', inputType: 'time'},
          {label: this.$t('email.lastReceiveTime'), name: 'lastReceiveTime', inputType: 'time'},
          {label: this.$t('email.customerServiceMailbox'), filterable: true, name: 'toAddr', inputType: 'select', data: serviceEmailData},
          {label: this.$t('email.categorySelect'), filterable: true, name: 'category', inputType: 'select', data: [{ label: this.$t('public.all'), value: '' }]},
          {
            label: this.$t('public.state'),
            name: 'status',
            inputType: 'select',
            data: [
              {label: this.$t('public.all'), value: ''},
              {label: this.$t('public.solved'), value: `finish__${this.$t('public.solved')}`},
              {label: this.$t('email.emailTodo'), value: `deal__${this.$t('email.emailTodo')}`},
              {label: this.$t('webchat.webchatTodo'), value: `undeal__${this.$t('webchat.webchatTodo')}`}
            ]
          },
          {label: this.$t('business.master'), name: 'ownercom', inputType: 'owner'},
          {label: this.$t('email.initiativeSendEmail'), name: 'initiative', inputType: 'checkbox', data: [{label: this.$t('public.yes'), value: `initiative__${this.$t('email.initiativeSendEmail')}`}]},
          {label: this.$t('email.processTimeout'), name: 'processTimeout', inputType: 'checkbox', data: [{label: this.$t('public.yes'), value: `processTimeout__${this.$t('email.processTimeout')}`}]},
          {label: this.$t('webchat.processResult'), filterable: true, name: 'finishKey', inputType: 'select', data: emailFinish}
        ]
        this.isbeforeMount = true
        this.routeToMe()
        this.search.email_all.isChildren.adv.advSearchOptions.localed = localedOptions
        this.formItemsConfig = config
      })
    },
    computed: {
      // 卡片列表数据
      cardList () {
        return deepClone(this.$store.state.email.emailList[this.activeName].list)
      },
      moreFlag () {
        if (this.$store.state[this.type][this.type + 'List'][this.activeName].more) {
          return true
        } else {
          return false
        }
      },
      count () {
        let countNew = this.$store.state.email.emailList[this.activeName].count
        if (this.pages === 0 && countNew) {
          this.pages = countNew / 10
        }
        return this.$store.state[this.type][this.type + 'List'][this.activeName].count
      },
      totalPage () {
        return Math.ceil(this.$store.state[this.type][this.type + 'List'][this.activeName].count / 10) || 0
      },
      // 邮件分类
      mailCategories () {
        let categoryList = this.search.mailCategorys || []
        let options = [{label: this.$t('public.all'), value: ''}]
        for (let i = 0; i < categoryList.length; i++) {
          options.push({label: categoryList[i].categoryName, value: categoryList[i]._id})
        }
        return options
      },
      // 待处理数
      tabPanes () {
        let todoNum = this.$store.state.email.todoNum
        if (todoNum > 99) {
          todoNum = '99+'
        }
        return [
          {name: this.$t('email.emailTodo') + todoNum, type: 'email_todo'},
          {name: this.$t('email.emailAll'), type: 'email_all'}
        ]
      }
    },
    methods: {
      // 路由跳转到邮件
      routerEnter () {
        this.$store.commit('BLANK', this.activeName)
      },
      routeToMe () {
        let query = this.$route.query
        if (query && query.active && query.emailNumber) {
          this.activeName = query.active
          if (query.status === 'timeOut') {
            this.$store.dispatch('queryEmailListById', {emailType: 'email_all', _id: query.emailNumber}).then((res) => {
              if (res && res.list.length) {
                this.$router.push('/index/email/' + query.active + '/' + query.emailNumber)
                this.$store.commit('email/REFRESH_BUS_RIGHT', Math.random())
              } else {
                this.$router.push('/index/email/')
              }
            })
          } else {
            this.$router.push('/index/email/' + query.active + '/' + query.emailNumber)
            this.$store.commit('email/REFRESH_BUS_RIGHT', Math.random())
          }
        } else if (this.$route.fullPath.indexOf('email_todo') > -1) {
//          邮件重复提醒跳转到邮件待处理列表的时候，没有query值，使用此处理方法
          this.activeName = 'email_todo'
          this.$router.push('/index/email/' + this.$route.params.tabType + '/' + this.$route.params.id + '/email_jump')
//          this.$router.push('/index/email/')
//          push路由操作放在了index.vue下操作
          this.$store.commit('email/REFRESH_BUS_RIGHT', Math.random())
        }
      },
      // 获取所有会话条数
      getAllCount () {
        this.allCount = 0
        let form = this.qu
        form.queryCount = true
        form.searchAllCount = true // 此参数是防止vuex的值被改动
        let activeName = this.activeName
        let more = false
        fetchMailList(this, activeName, form).then((resp) => {
          delete this.qu.searchAllCount
          if (resp && resp.success) {
            this.allCount = resp.count
            this.$store.commit('email/SET_EMAIL_MORE', {activeName, more})
            this.loading = false
          }
        })
      },
      /*
      * 快捷搜索时间
      * */
      searchDataReturn (value) {
        let nowTime = new Date()
        let mtDate = nowTime.getTime()
        let startTime = ''
        let endTime = getFormatDateTime(new Date()).split(' ')[0] + ' 23:59:59'
        if (value === 'week') {
          // 近一周
          startTime = getFormatDateTime(new Date(mtDate - 3600 * 1000 * 24 * 6)).split(' ')[0] + ' 00:00:00'
        } else if (value === 'today') {
          // 今天
          startTime = getFormatDateTime(new Date(mtDate)).split(' ')[0] + ' 00:00:00'
        } else if (value === 'yesterday') {
          // 昨天
          startTime = getFormatDateTime(new Date(mtDate - 3600 * 1000 * 24)).split(' ')[0] + ' 00:00:00'
          endTime = getFormatDateTime(new Date(mtDate - 3600 * 1000 * 24)).split(' ')[0] + ' 23:59:59'
        } else if (value === 'month') {
          // 近一月
          startTime = getFormatDateTime(new Date(mtDate - 3600 * 1000 * 24 * 29)).split(' ')[0] + ' 00:00:00'
        } else {
          endTime = ''
        }
        let searchQuery = {
          createTime$begin: startTime,
          createTime$end: endTime
        }
        return searchQuery
      },
      // 获取options下所有key
      getSubFinishKey (superKey) {
        let result = [superKey]
        let finishMap = this.getSubFinishMap(superKey)
        let iteratorDic = function (options = []) {
          for (let i = 0; i < options.length; i++) {
            result.push(options[i].key)
            if (options[i].options && options[i].options.length > 0) {
              iteratorDic(options[i].options)
            }
          }
        }
        iteratorDic(finishMap)
        return result
      },

      // 获取options对象
      getSubFinishMap (superKey) {
        let result = []
        let options = this.getChannelDicByType('email') || []
        for (let i = 0; i < options.length; i++) {
          if (superKey === options[i].key) {
            result = options[i].options
            break
          }
          let options2 = options[i].options || []
          for (let j = 0; j < options2.length; j++) {
            if (superKey === options2[j].key) {
              result = options2[j].options
              break
            }
            let options3 = options2[j].options || []
            for (let k = 0; k < options3.length; k++) {
              if (superKey === options3[k].key) {
                result = options3[k].options
                break
              }
            }
          }
        }
        return result
      },

      // 打开主动发送邮件模块
      sendEmail () {
        this.$router.push({path: '/index/email/send_email'})
      },
      changeCardItem () {
        this.$emit('changeCardItem')
      },
      // 路由变化导致tab切换
      changeTabType () {
        this.allCount = 0
        this.searchStatus = ''  // 当前的高级搜索中的状态
        this.this.$nextTick(function () {
          this.activeName = this.currentTabType
        })
        this.$store.commit('BLANK', this.currentTabType)
      },
      // tab切换
      changeTab (tabName) {
        this.allCount = 0
        this.searchStatus = ''  // 当前的高级搜索中的状态
        this.clearSearchQuery()
        this.createTimeInit()
        this.activeName = tabName
        this.search.isSearch = true
        this.search.isAdvSearch = false
        this.$router.push({path: '/index/email/'})
        this.$store.commit('BLANK', this.activeName)
        bus.$emit('emailClickTabFun', tabName)
        if (this.activeName === 'email_todo' && this.$store.state.email.emailList.email_todo.init) {
          return
        }
        this.loading = true
        let queryData = {
          query: '',
          page: 1,
          limit: 10
        }
        this.search[this.activeName].isChildren.lastQuery = queryData
        fetchMailList(this, this.activeName, queryData).then(() => {
          this.pages = 0
          this.loading = false
        })
      },
      // 翻页
      turnPage (pageNum) {
        this.allCount = 0
        if (this.search.isSearch && pageNum < 2) {
          this.search.isSearch = false
          return
        }
        this.search.isSearch = false
        this.loading = true
        let morePage = 1
        if (pageNum >= this.pages && pageNum % this.pages === 0) {
          morePage = pageNum / this.pages + 1
        } else {
          morePage = Math.floor(pageNum / this.pages + 1)
        }
        this.search[this.activeName].pagination.currentPage = pageNum
        let queryData = {}
        queryData = Object.assign({}, this.search[this.activeName].isChildren.lastQuery, { page: pageNum, morePage })
        fetchMailList(this, this.activeName, queryData).then(() => {
          this.loading = false
        })
      },
      // 快捷搜索
      handlerQuickSelect (value) {
        this.allCount = 0
        this.loading = true
        this.searchStatus = ''  // 当前的高级搜索中的状态
        this.search.isSearch = true
        this.search[this.activeName].isChildren.nomalForm.value = value

        let formData = this.search[this.activeName].isChildren.nomalForm
        let queryData = deepClone({category: formData.value, query: formData.query})

        Object.assign(queryData, {
          page: 1,
          limit: 10,
          emailType: this.activeName
        })

        this.search[this.activeName].pagination.currentPage = 1
        this.search[this.activeName].isChildren.lastQuery = queryData
        fetchMailList(this, this.activeName, queryData).then(() => {
          this.loading = false
        })
      },
      // 处理高级搜索中的下拉框改变
      handlerSelectChange (selectObj) {
        let selectName = selectObj.selectName
        let selectValue = selectObj.selectValue
        let currentTab = this.search[this.activeName]
        // this.search[this.activeName].isChildren.adv.badgeList = {} // 清除高级搜索项
        this.search.isAdvSearch = false
        if (selectName === 'owner' || selectName === 'ownercom' || selectName === 'ownerdep') {
          currentTab.isChildren.adv.form.ownercom = null
          currentTab.isChildren.adv.form.owner = null
          currentTab.isChildren.adv.form.agent = null
          currentTab.isChildren.adv.form.ownerdep = null
          if (selectObj.selectName === 'owner') {
            currentTab.isChildren.adv.form.agent = selectObj.selectValue
          } else {
            currentTab.isChildren.adv.form[selectObj.selectName] = selectObj.selectValue
          }
        }
        if (selectName === 'toAddr') {
          let mailCategorys = this.search.mailCategorys || []
          let resultCategories = [{ label: this.$t('public.all'), value: '' }]
          for (let i = 0; i < mailCategorys.length; i++) {
            let category = mailCategorys[i]
            if (selectValue === category.relateMailAddr) {
              resultCategories.push({ label: category.categoryName, value: `${category._id}__${category.categoryName}` })
            }
          }
          currentTab.isChildren.adv.advSearchOptions.localed.forEach((item) => {
            if (item.name === 'category') {
              currentTab.isChildren.adv.form.category = ''
              item.data = resultCategories
            }
          })
        }
      },
      // 清除高级搜索的条件
      removeBadge () {
        this.advSearch(true)
        this.search.isAdvSearch = false
        this.clearChecked = Math.random() + ''
        this.createTimeInit()
      },
      // 高级搜索
      advSearch (reset) {
        window._hmt && window._hmt.push(['_trackEvent', '其他统计', this.activeName + ' 高级搜索'])
        this.allCount = 0
        this.search.isAdvSearch = true
        this.loading = true
        if (reset) {
          this.clearSearchQuery()
        }

        let form = this.search[this.activeName].isChildren.adv.form
        let searchQuery = deepClone(form)
        let createTime = form.createTime
        let lastReceiveTime = form.lastReceiveTime

        // 收发件人地址
        if (searchQuery.fromAddr) {
          searchQuery['from.addr'] = searchQuery.fromAddr
          delete searchQuery.fromAddr
        }
        if (searchQuery.toAddr) {
          searchQuery['to.addr'] = searchQuery.toAddr
          delete searchQuery.toAddr
        }

        // 创建时间
        if (createTime) {
          if (createTime[0]) {
            searchQuery.createTime_begin_date = getFormatDateTime(createTime[0])
          }
          if (createTime[1]) {
            searchQuery.createTime_end_date = getFormatDateTime(createTime[1])
          }
          delete searchQuery.createTime
        }

        // 最后接受时间
        if (lastReceiveTime) {
          if (lastReceiveTime[0]) {
            searchQuery.lastReceiveTime_begin_date = getFormatDateTime(lastReceiveTime[0])
          }
          if (lastReceiveTime[1]) {
            searchQuery.lastReceiveTime_end_date = getFormatDateTime(lastReceiveTime[1])
          }
          delete searchQuery.lastReceiveTime
        }
        let tempObj = this.advSearchBack(searchQuery)
        this.search[this.activeName].isChildren.adv.badgeList = tempObj

        this.searchStatus = searchQuery.status || ''
        // 结束类型
        if (searchQuery.finishKey) {
          searchQuery.finishKey = {'$in': this.getSubFinishKey(searchQuery.finishKey)}
        }
        Object.assign(searchQuery, {
          page: 1,
          limit: 10
        })
        this.search[this.activeName].pagination.currentPage = 1
        this.search[this.activeName].isChildren.lastQuery = searchQuery
        this.currentAdvSesrch = searchQuery
        fetchMailList(this, this.activeName, searchQuery).then(() => {
          this.loading = false
        })
      },
      // 高级搜索回调
      advSearchBack (searchQuery) {
        let tmpObj = {}
        let that = this
        for (let key in searchQuery) {
          if (searchQuery[key] && typeof searchQuery[key] === 'string') {
            if (searchQuery[key].match(/__/)) {
              tmpObj[key] = searchQuery[key].substr(searchQuery[key].indexOf('__') + 2)
              searchQuery[key] = searchQuery[key].substr(0, searchQuery[key].indexOf('__'))
            } else {
              tmpObj[key] = searchQuery[key]
            }
          }
          if (searchQuery[key] && Array.isArray(searchQuery[key]) && searchQuery[key].length > 0) {
            let tmpArr = []
            let tmpArr2 = []
            for (let i = 0; i < searchQuery[key].length; i++) {
              tmpArr.push(searchQuery[key][i].substr(searchQuery[key].indexOf('__') + 2))
              tmpArr2.push(searchQuery[key][i].substr(0, searchQuery[key].indexOf('__')))
            }
            tmpObj[key] = tmpArr
            searchQuery[key] = tmpArr2
          }
          if (searchQuery[key] && key === 'initiative') {
            tmpObj[key] = that.$t('email.initiativeSendEmail')
          }
          if (searchQuery[key] && key === 'processTimeout') {
            tmpObj[key] = that.$t('email.processTimeout')
          }
        }
        return tmpObj
      },
      // 输入框搜索
      normalSearch (value) {
        this.allCount = 0
        this.search[this.activeName].isChildren.adv.badgeList = {} // 清除高级搜索项
        this.search.isSearch = true
        this.loading = true
        this.search.isAdvSearch = false
        this.search[this.activeName].isChildren.nomalForm.query = value

        let query = {
          emailType: this.activeName,
          page: 1,
          limit: 10
        }
        if (value) {
          query.query = value
        }
        if (this.search[this.activeName].isChildren.nomalForm.value) {
          let selectValue = this.search[this.activeName].isChildren.nomalForm.value
          Object.assign(query, (typeof selectValue === 'object') ? selectValue : { category: selectValue })
        }

        this.search[this.activeName].pagination.currentPage = 1
        this.search[this.activeName].isChildren.lastQuery = query
        fetchMailList(this, this.activeName, query).then(() => {
          this.loading = false
        })
      },
      // 创建时间初始化
      createTimeInit () {
        let week = this.searchDataReturn('week')
        this.search.email_all.isChildren.adv.form.createTime = [new Date(week.createTime$begin), new Date(week.createTime$end)]
      },
      // 清空高级搜索的条件
      clearSearchQuery () {
        this.allCount = 0
        let currentTab = this.search[this.activeName]
        currentTab.pagination.currentPage = 1
        for (let key in currentTab.isChildren.adv.form) {
          if (Array.isArray(currentTab.isChildren.adv.form[key])) {
            currentTab.isChildren.adv.form[key] = []
          } else {
            currentTab.isChildren.adv.form[key] = null
          }
          if (key === 'initiative') {
            currentTab.isChildren.adv.form.initiative = false
          }
          if (key === 'processTimeout') {
            currentTab.isChildren.adv.form.processTimeout = false
          }
          for (let key in this.search[this.activeName].isChildren.nomalForm) {
            this.search[this.activeName].isChildren.nomalForm[key] = null
          }
        }
        this.search[this.activeName].isChildren.adv.badgeList = null
        this.currentAdvSesrch = null
      },
      // 刷新列表
      handleRefresh (flag) {
        this.allCount = 0
        if (this.search.isAdvSearch) {
          this.advSearch()
        } else {
          this.normalSearch(this.search[this.activeName].isChildren.nomalForm.query)
        }
        if (flag) {
          this.$router.push({path: '/index/email/'})
        }
      },
 //      获取渠道结束类型
      getChannelDicByType (type) {
        let channelDic = this.$getCache('channelDic')
        let result = []
        for (let i = 0; i < channelDic.length; i++) {
          if (channelDic[i].type === type) {
            result = channelDic[i].options
            break
          }
        }
        return result
      },
      handleConfirmNewItemsConfig ({data: formItemsConfig, done}) {
        this.$store.dispatch('saveAdvSearchConfig', {
          searchType: 'EmailCardGroup',
          config: formItemsConfig
        }).then(() => {
          this.formItemsConfig = formItemsConfig
          done()
        })
      }
    },
    components: {
      EmailCard,
      Search,
      'v-select': Select,
      CardGroupSolt,
      InputSearch,
      AdvancedSearch,
      Pagination,
      AdvSchBadge,
      Refresh,
      sendEmail
    }
  }
  function fetchMailList (self, tabType, data) {
    self.qu = deepClone(data)
    data.type = tabType
    return self.$store.dispatch('queryEmailList', data)
  }
  function getFinishType (finishOption) {
    let finishKeys = []
    for (let i = 0; i < finishOption.length; i++) {
      finishKeys.push({label: finishOption[i].name, value: `${finishOption[i].key}__${finishOption[i].name}`})
      let level2 = deepClone(finishOption[i].options)
      if (level2) {
        for (let m = 0; m < level2.length; m++) {
          level2[m].name = finishOption[i].name + '->' + level2[m].name
          finishKeys.push({label: level2[m].name, value: `${level2[m].key}__${level2[m].name}`})
          let level3 = deepClone(level2[m].options)
          if (level3) {
            for (let n = 0; n < level3.length; n++) {
              level3[n].name = level2[m].name + '->' + level3[n].name
              finishKeys.push({label: level3[n].name, value: `${level3[n].key}__${level3[n].name}`})
            }
          }
        }
      }
    }
    return finishKeys
  }
</script>
<style lang="stylus" scoped>
</style>
